<template>
  <view class="wallet p-20">
    <view class="my-card wallet-bar flex flex-column">
      <view class="flex flex-1 items-center justify-center">
        <view>
          <u-text align="center" :text="`可提现金额（元）`" color="#fff"></u-text>
          <u-text
            align="center"
            color="#fff"
            size="24"
            bold
            :text="Number(userStore.riderInfo.rider_amount_total).toFixed(2)"
            class="mt-20"
          ></u-text>
          <u-button type="success" shape="circle" class="mt-20" @tap="handleToWithdrawal">去提现</u-button>
        </view>
      </view>
      <view class="flex justify-between">
        <view>
          <u-text text="今日收益" color="#fff"></u-text>
          <u-text align="center" :text="Number(userStore.riderInfo.today_amount).toFixed(2)" color="#fff"></u-text>
        </view>
        <view>
          <u-text text="本周收益" color="#fff"></u-text>
          <u-text align="center" :text="Number(userStore.riderInfo.week_amount).toFixed(2)" color="#fff"></u-text>
        </view>
      </view>
    </view>
    <view class="my-card mt-20">
      <u-cell-group :border="false">
        <!-- #ifdef MP-WEIXIN -->
        <u-cell
          :border="false"
          title="绑定微信"
          is-link
          @tap="handleBindWechat"
          :value="userStore.isBindWechat ? '已绑定' : '未绑定'"
        ></u-cell>
        <!-- #endif -->
        <u-cell :border="false" title="我的银行卡" is-link @tap="handleToMyCard"></u-cell>
        <u-cell :border="false" title="收入记录" is-link @tap="toWalletAccount"></u-cell>
        <u-cell :border="false" title="提现记录" is-link @tap="toWithdrawalRecord"></u-cell>
      </u-cell-group>
    </view>
  </view>
</template>

<script setup>
  import { useUserStore } from "../../store/user.js";
  import { onShow } from "@dcloudio/uni-app";

  const userStore = useUserStore();

  function handleBindWechat() {
    if (userStore.isBindWechat) {
      uni.showModal({
      title: "提示",
      content: "是否继续解绑微信",
      success: (res) => {
        if (res.confirm) {
          userStore.fetchUnbindWechat();
        }
      },
    });
    } else {
      uni.showModal({
        title: "提示",
        content: "是否继续绑定当前微信",
        success: (res) => {
          if (res.confirm) {
            uni.login({
              provider: "weixin",
              success: (result) => {
                userStore.fetchBindWechat({ code: result.code });
              },
            });
          }
        },
      });
    }
  }

  function handleToMyCard() {
    uni.navigateTo({
      url: "/pages/bankcard-list/bankcard-list",
    });
  }

  function toWalletAccount() {
    uni.navigateTo({
      url: "/pages/wallet-account/wallet-account",
    });
  }

  function handleToWithdrawal() {
    uni.navigateTo({
      url: "/pages/withdrawal/withdrawal",
    });
  }

  function toWithdrawalRecord() {
    uni.navigateTo({
      url: "/pages/withdrawal-record/withdrawal-record",
    });
  }

  onShow(() => {});
</script>

<style lang="scss" scoped>
  .wallet-bar {
    background-color: $u-primary;
    height: 350rpx;
  }
</style>
